<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" method="post" action="add" id="form-knowledge-add" onsubmit="return false;" enctype="multipart/form-data">
			<div class="form-group">	
				<label class="col-sm-3 control-label">标题：</label>
				<div class="col-sm-8">
					<input id="title" name="title" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">封面：</label>
				<div class="col-sm-8">
					<input id="file" name="file" class="form-control" type="file">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">内容：</label>
				<div class="col-sm-8">
					<input id="content" name="content" type="hidden">
				    <div class="summernote"></div>
					<!-- <input id="content" name="content" class="form-control" type="text"> -->
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<!-- <input id="status" name="status" class="form-control" type="text"> -->
					<select name="status" id="status" class="form-control m-b" th:with="type=${@dict.getType('hl_knowledge_status')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<!-- <div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div> -->
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
    <script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
    <script type="text/javascript">
		var prefix = ctx + "knowledge";
		
		 $('.summernote').summernote({
				height : '220px',
				lang : 'zh-CN'
			});
		
		$("#form-knowledge-add").validate({
			rules:{
				title:{
					required:true,
				}
			},
			submitHandler: function(form) {
				var sHTML = $('.summernote').code();
				$("#content").val(sHTML);
				var files = $('#file').prop('files');
	            var data = new FormData();
	            data.append('file', files[0]);
	            data.append('title', $("#title").val());
	            data.append('content',sHTML);
	            data.append('status', $("#status").val());

	            $.ajax({
	                type: 'POST',
	                url: prefix + "/add",
	                data: data,
	                cache: false,
	                processData: false,
	                contentType: false,
	                success: function (ret) {
	                    console.info(ret);
						$.modal.close();
						window.parent.location.reload();
	                }
	            });
				/* form.submit();
				$.modal.close();
				window.parent.location.reload(); */
				//$.operate.save(prefix + "/add", $('#form-knowledge-add').serialize());
			}
		});
		
		/* function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-knowledge-add').serialize());
	        }
	    } */
	</script>
</body>
</html>
